package dabs.engine.plant;

import dabs.engine.control.ComponentCommand;
import dabs.engine.environment.AcceptsModifier;
import dabs.engine.environment.Modifier;
import dabs.engine.environment.TemporaryDisable;
import dabs.engine.messaging.Notification;
import dabs.engine.messaging.NotificationHandler;

public class Condenser extends Converter implements AcceptsModifier{
	private static final long serialVersionUID = -1755486795151965016L;

	public Condenser(NotificationHandler mailBox, String name, double conversionRate) {
		super(mailBox, name, conversionRate);
	}
	
	public double getCondensingSpeed() { return getConversionRate(); }
	
	public void setCondensingSpeed( int condensingSpeed ) { 
		if ( isDeactivated() == false ) {
			setConversionRate(condensingSpeed); 
			passMessage(new Notification(getName(), "Speed set to " + condensingSpeed + "%."));
		} else {
			passMessage( new Notification(getName(), "is stalled") );
		}
		
	}
	
	@Override
	protected void inactivatedModifier(Modifier modifier) {
		super.inactivatedModifier(modifier);
		if (modifier instanceof TemporaryDisable) {
			passMessage(new Notification(getName(), "is now active again"));
		}
	}
	
	@Override
	public void tick() {
		getNewHydroState().update(getConversionRate(), true, getOutputs());
		super.tick();
	}
	
	@Override
	public void runCommand(ComponentCommand command) {
		assert(command.getDestination().equals(getName()));
		int newSpeed = Integer.parseInt(command.getArguments().get(0)); //Line to be changed depending on arguments.
		if (newSpeed <= 100 && newSpeed >= 0){
			setCondensingSpeed(newSpeed);
		}
		else{
			passMessage(new Notification(getName(), "Speed  must be set to a value between 0 and 100"));
		}
	}
	
}
